package ltd.hyangyang.vegetable.controller;

import ltd.hyangyang.vegetable.entity.Admin;
import ltd.hyangyang.vegetable.service.AdminService;
import ltd.hyangyang.vegetable.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("login")
    public Result<Admin> login(String account,String password){
        //查询账号是否存在
        Admin admin =adminService.login(account,password);
        return Result.success(admin);
    }

    @RequestMapping("getAdminInfo")
    public Result<Admin> adminInfo(HttpServletRequest request){
        String account = request.getHeader("account");
        Admin admin =adminService.adminInfo(account);
        return Result.success(admin);
    }
}
